package com.qfedu.meidijiaju.controller;

import com.qfedu.meidijiaju.entity.ResponseData;
import com.qfedu.meidijiaju.entity.Sbgl;
import com.qfedu.meidijiaju.entity.HcShopping;
import com.qfedu.meidijiaju.service.SbglService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "设备管理模块接口")
@RestController
public class SbglController {
    @Autowired
    private SbglService sbglService;
    @ApiOperation(value = "获取当前用户已添加的设备")
    @RequestMapping(value = "/Sbgl/querySb",method = RequestMethod.GET)
    public ResponseData<List<Sbgl>> querySb(int uid) {
        int count = sbglService.querySbCount(Integer.parseInt(String.valueOf(uid)));
        List<Sbgl> result = sbglService.querySbByUid(uid);
        ResponseData<List<Sbgl>> responseData = new ResponseData<>();

        if (count != 0) {
            responseData.setCode(0);
            responseData.setCount(count);
            responseData.setData(result);

        }
        return responseData;

    }
    @ApiOperation(value = "当前用户根据型号获取对应设备")
    @RequestMapping(value = "/Sbgl/querySbByXhId",method = RequestMethod.GET)
    public ResponseData<List<HcShopping>> querySbByXhId(int xhid) {
        List<HcShopping> result = sbglService.querySbByXhId(xhid);
        ResponseData<List<HcShopping>> responseData = new ResponseData<>();

        if (result!=null) {
            responseData.setCode(0);
            responseData.setData(result);

        }
        return responseData;

    }
    @ApiOperation(value = "当前用户添加设备")
    @RequestMapping(value = "/Sbgl/addSb",method = RequestMethod.GET)
    public ResponseData<String> addSb(Sbgl sbgl) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean addSb = sbglService.addSb(sbgl);
        if (addSb) {
            responseData.setCode(0);
            responseData.setMsg("添加成功");

        }
        return responseData;

    }
    @ApiOperation(value = "当前用户删除设备")
    @RequestMapping(value = "/Sbgl/deleteSb",method = RequestMethod.GET)
    public ResponseData<String> deleteSb(Sbgl sbgl) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean addSb = sbglService.deleteSb(sbgl);
        if (addSb) {
            responseData.setCode(0);
            responseData.setMsg("删除成功");

        }
        return responseData;

    }
}
